Skip to content

Fix editor state leaking when switching automations, scripts, or scenes - #53826

Merged
bramkragten merged 5 commits into
devfrom
remount-editor-on-item-switch
Aug 27, 2026
Merged

Fix editor state leaking when switching automations, scripts, or scenes#53826
bramkragten merged 5 commits into
devfrom
remount-editor-on-item-switch

Conversation

@MindFreeze

Copy link
Copy Markdown
Member

Proposed change

Opening another automation, script, or scene while already editing one reused the same editor element, so YAML mode, undo history, pending registry edits, and scene live control could carry over. Saving could then write the previous item's content onto the newly opened item.

HassRouterPage now recreates the page when the remaining path is a single item id and that id changes. Those pages are also not cached. Nested routers (for example ha-config-automation) stay in place so cached dashboards survive. In-flight editor loads are ignored after disconnect, and a scene editor in live mode restores stored states when it is torn down.

Saving a new item remounts as well, so YAML mode is not kept after the first save.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • I have followed the perfect PR recommendations
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

To help with the load of incoming pull requests:

Recreate the page when the item id in the route changes so YAML mode,
undo history, and scene live state cannot carry over to the next item.
@github-actions github-actions Bot added the Tests: Unit Related to Vitest unit tests label Aug 27, 2026
@MindFreeze MindFreeze added this to the 2026.9 milestone Aug 27, 2026
Path-shape matching remounted nested config routers, Lovelace, and
developer tools. Recreate only where edit/show routes opt in.
A remounted editor starts in review; disconnect only needs to drop
the subscription, not undo device changes from live mode.
@MindFreeze
MindFreeze marked this pull request as ready for review August 27, 2026 10:23
@bramkragten

Copy link
Copy Markdown
Member

This means that when saving an automation for the first time (from new -> id) also recreates the editor?

Comment thread src/layouts/hass-router-page.ts Outdated
oldTail !== newTail
) {
delete this._cache[newPage];
this._createPanel(routerOptions, newPage, routeOptions);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should not just create the panel? It skips the loading screen right now, and a dynamically imported panel would fail?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing it to go through load

Comment thread src/layouts/hass-router-page.ts Outdated
routeOptions.itemId &&
oldTail !== newTail
) {
delete this._cache[newPage];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will never be in the cache anyway right?

@MindFreeze

Copy link
Copy Markdown
Member Author

This means that when saving an automation for the first time (from new -> id) also recreates the editor?

Yes, we will get a repaint. I think that's ok

@bramkragten

Copy link
Copy Markdown
Member

For the scene editor, probably unrelated to this PR, but shouldn't leaving the page also call _exitLiveMode? 🤔

@MindFreeze

Copy link
Copy Markdown
Member Author

For the scene editor, probably unrelated to this PR, but shouldn't leaving the page also call _exitLiveMode? 🤔

Will create a follow up PR for this

Clear the current page instead of calling _createPanel directly so
load and the loading screen still run. Drop the redundant cache delete.
bramkragten
bramkragten previously approved these changes Aug 27, 2026
Nested submit/cancel schedules a nextRender callback that ran after
Vitest tore down HTMLElement, failing CI with an unhandled rejection.
@bramkragten
bramkragten merged commit 27cbbdb into dev Aug 27, 2026
31 checks passed
@bramkragten
bramkragten deleted the remount-editor-on-item-switch branch August 27, 2026 15:04
bramkragten added a commit that referenced this pull request Aug 27, 2026
…es (#53826)

* Fix editor state leaking when switching automations, scripts, or scenes

Recreate the page when the item id in the route changes so YAML mode,
undo history, and scene live state cannot carry over to the next item.

* Declare itemId on editor routes instead of guessing from the path

Path-shape matching remounted nested config routers, Lovelace, and
developer tools. Recreate only where edit/show routes opt in.

* Do not restore scene live states when the editor is torn down

A remounted editor starts in review; disconnect only needs to drop
the subscription, not undo device changes from live mode.

* Use the normal create path when remounting itemId pages

Clear the current page instead of calling _createPanel directly so
load and the loading screen still run. Drop the redundant cache delete.

* Fix dialog-form tests leaking focus restore after jsdom teardown

Nested submit/cancel schedules a nextRender callback that ran after
Vitest tore down HTMLElement, failing CI with an unhandled rejection.
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cherry-picked cla-signed Tests: Unit Related to Vitest unit tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants